import request from '@/axios'
import { useUserStoreWithOut } from '@/store/modules/user'

const BASEURL = '/changhu'
const BASEURL2 = '/api'

/** 查询资源菜单树列表 */
export const getMenuListApi = (data) => {
  return request.post({ url: BASEURL + '/sysResource/dataList', data: data })
}

/** 新增或修改资源菜单信息 */
export const sysResourceSaveOrUpdate = (data) => {
  return request.post({ url: BASEURL + '/sysResource/saveOrUpdate', data: data })
}

/** 根据id查询资源菜单 */
export const sysResourceGetById = (params) => {
  return request.post({ url: BASEURL + '/sysResource/get', params: params })
}

/** 根据id删除资源菜单 */
export const sysResourceDeleteById = (params) => {
  return request.post({ url: BASEURL + '/sysResource/delete', params: params })
}

/** 查询机构菜单树列表 */
export const sysOrgDataList = (data) => {
  return request.post({ url: BASEURL + '/sysOrg/dataList', data: data })
}

/** 新增或修改机构菜单信息 */
export const sysOrgSaveOrUpdate = (data) => {
  return request.post({ url: BASEURL + '/sysOrg/saveOrUpdate', data: data })
}

/** 根据id查询机构信息，不包含子机构 */
export const sysOrgGetById = (params) => {
  return request.post({ url: BASEURL + '/sysOrg/get', params: params })
}

/** 根据id删除机构菜单 */
export const sysOrgDeleteById = (params) => {
  return request.post({ url: BASEURL + '/sysOrg/delete', params: params })
}

/** 分页查询部门列表 */
export const sysDepartmentPageDataList = (data) => {
  return request.post({ url: BASEURL + '/sysDepartment/pageDataList', data: data })
}

/** 查询部门菜单树列表 */
export const sysDepartmentDataList = (data) => {
  return request.post({ url: BASEURL + '/sysDepartment/dataList', data: data })
}

/** 新增或修改部门信息 */
export const sysDepartmentSaveOrUpdate = (data) => {
  return request.post({ url: BASEURL + '/sysDepartment/saveOrUpdate', data: data })
}

/** 根据id查询部门信息 */
export const sysDepartmentGetById = (params) => {
  return request.post({ url: BASEURL + '/sysDepartment/get', params: params })
}

/** 根据id删除部门 */
export const sysDepartmentDeleteById = (params) => {
  return request.post({ url: BASEURL + '/sysDepartment/delete', params: params })
}
/** 获取用户列表 */
export const sysUserDataList = (data) => {
  return request.post({ url: BASEURL + '/sysUser/dataList', data: data })
}
/** 分页获取用户列表 */
export const sysUserPageDataList = (params, data) => {
  return request.post({ url: BASEURL + '/sysUser/pageDataList', params: params, data: data })
}

/** 新增或修改用户信息 */
export const sysUserSaveOrUpdate = (data) => {
  return request.post({ url: BASEURL + '/sysUser/saveOrUpdate', data: data })
}

/** 根据id查询用户信息 */
export const sysUserGetById = (params) => {
  return request.post({ url: BASEURL + '/sysUser/get', params: params })
}

/** 根据id删除用户 */
export const sysUserDeleteById = (params) => {
  return request.post({ url: BASEURL + '/sysUser/delete', params: params })
}
/** 根据用户id查询角色列表，owned拥有该角色 */
export const sysUserQueryRoleByUserId = (params) => {
  return request.post({ url: BASEURL + '/sysUser/queryRoleByuserId', params: params })
}
/** 重置密码 */
export const sysUserResetPwd = (params) => {
  return request.post({ url: BASEURL + '/sysUser/resetPwd', params: params })
}
/** 查询角色对应的用户列表，根据机构查询，isOwned标识是否拥有该用户 */
export const sysRoleQueryUserByRoleId = (params) => {
  return request.post({ url: BASEURL + '/sysRole/queryUserByRoleId', params: params })
}

/** 分页获取角色列表 */
export const sysRolePageDataList = (data) => {
  return request.post({ url: BASEURL + '/sysRole/pageDataList', data: data })
}

/** 新增或修改角色信息 */
export const sysRoleSaveOrUpdate = (data) => {
  return request.post({ url: BASEURL + '/sysRole/saveOrUpdate', data: data })
}

/** 根据id查询角色信息 */
export const sysRoleGetById = (params) => {
  return request.post({ url: BASEURL + '/sysRole/get', params: params })
}

/** 根据id删除角色 */
export const sysRoleDeleteById = (params) => {
  return request.post({ url: BASEURL + '/sysRole/delete', params: params })
}

/** 分页获取快捷列表 */
export const commonUsagesDataList = (params) => {
  return request.post({ url: BASEURL + '/commonUsages/dataList', params: params })
}

/** 新增快捷信息 */
export const commonUsagesSave = (data) => {
  return request.post({ url: BASEURL + '/commonUsages/save', data: data })
}

/** 根据id删除快捷 */
export const commonUsagesDeleteById = (params) => {
  return request.post({ url: BASEURL + '/commonUsages/delete', params: params })
}
/** 查询角色对应的资源列表，包含所有资源，isOwned标识是否拥有该资源 */
export const sysResourceQueryEpResourceTree = (params) => {
  return request.post({ url: BASEURL + '/sysResource/queryEpResourceTree', params: params })
}

/** 批量给角色分配菜单那权限 */
export const sysPermissionSaveRoleResource = (data) => {
  return request.post({ url: BASEURL + '/sysPermission/saveRoleResource', data: data })
}

/** 批量给角色分配用户 */
export const sysGrantBatchGrantUser = (data) => {
  return request.post({ url: BASEURL + '/sysGrant/batchGrantUser', data: data })
}
/** 批量给用户分配角色 */
export const sysGrantBatchGrantRole = (data) => {
  return request.post({ url: BASEURL + '/sysGrant/batchGrantRole', data: data })
}

/** 登录 */
export const authLogin = (data) => {
  return request.post({ url: BASEURL2 + '/auth/login', data: data })
}

/** 登出 */
export const authLogout = () => {
  const userStore = useUserStoreWithOut()

  return request.post({ url: BASEURL2 + '/auth/logout', params: { Key: userStore.getKey } })
}

/** 获取项目列表 */
export const sysProjectDataList = () => {
  return request.post({ url: BASEURL + '/sysProject/dataList' })
}

/** 操作日志分页查询 */
export const sysOperateLogPageDataList = (params, data) => {
  return request.post({ url: BASEURL + '/sysOperateLog/pageDataList', params: params, data: data })
}
